﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using Register.Model;
using Register.Command;
using Register.DALFactory;
namespace Register.BLL
{
    /// <summary> 
    /// FileName: ProvinceOrCityBLL.cs    
    /// CLRVersion: 4.0.30319.269    
    /// Author: DoubleZ    
    /// Corporation:     
    /// Description:     
    /// DateTime: 2012/6/28 20:15:32    
    /// </summary>
  public  class ProvinceOrCityBLL
    {
      private static String typeNameKey = "IProvinceOrCityDALKey";
      
      public static List<Province> GetProvinceList( )
      {
          try
          {
              IProvinceOrCityDAL iParamter = DALFactory<IProvinceOrCityDAL>.Create(typeNameKey);

              return iParamter.GetProvinceList();
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }

      /// <summary>
      /// 获取城市信息
      /// </summary>
      /// <returns></returns>
      public static List<City> GetCityList()
      {
          try
          {
              IProvinceOrCityDAL iParamter = DALFactory<IProvinceOrCityDAL>.Create(typeNameKey);

              return iParamter.GetCityList();
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      /// <summary>
      /// 添加省信息
      /// </summary>
      /// <param name="model"></param>
      /// <returns></returns>
      public static bool AddProvinceInfo(Province model)
      {
          IProvinceOrCityDAL iProvinceInfo = DALFactory<IProvinceOrCityDAL>.Create(typeNameKey);
          try
          {
              if (iProvinceInfo.InsertProvinceInfo(model) > 0)
                  return true;
              else
                  return false;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      /// <summary>
      /// 添加城市信息
      /// </summary>
      /// <param name="model"></param>
      /// <returns></returns>
      public static bool AddCityInfo(City model)
      {
          IProvinceOrCityDAL iCitynfo = DALFactory<IProvinceOrCityDAL>.Create(typeNameKey);
          try
          {
              if (iCitynfo.InsertCityInfo(model) > 0)
                  return true;
              else
                  return false;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      /// <summary>
      /// 根据城市ID获取城市名
      /// </summary>
      /// <param name="paramID"></param>
      /// <returns></returns>
      public static string GetCityNameById(string CityID)
      {
          IProvinceOrCityDAL iCityInfo = DALFactory<IProvinceOrCityDAL>.Create(typeNameKey);
          try
          {
              return iCityInfo.GetCityName(CityID);

          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
      /// <summary>
      /// 根据省区ID获取省区名
      /// </summary>
      /// <param name="paramID"></param>
      /// <returns></returns>
      public static string GetProvinceNameById(string CityID)
      {
          IProvinceOrCityDAL iProvinceInfo = DALFactory<IProvinceOrCityDAL>.Create(typeNameKey);
          try
          {
              return iProvinceInfo.GetProvinceName(CityID);

          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
    }
}
